<?php
namespace Admin\Controller;

use Common\Base\ControllerBase;
use Common\Logic\Common\ZoneLogic;

class ZoneController extends ControllerBase
{
    public $L_zone;
    
    public function _initialize()
    {
        $this->L_zone = new ZoneLogic();
    }
    
    public function index()
    {
        $pid = (int)I('get.pid'); if($pid < 1){ $pid = 0; }
        $infos = $this->L_zone->getZone(2, array('pid'=>$pid));
        $this->assign('infos', $infos);
        $this->assign('levels', $this->L_zone->levels);
        $ups = array();
        if($pid > 0){
            $this->L_zone->getUps($pid, $ups);
            $ups = array_reverse($ups);
        }
        $this->assign('ups', $ups);
        $this->assign('province_select', $this->L_zone->getProvinceSelect(-1, 'province_id', 'getCity(this.value)'));
        $this->assign('city_select', $this->L_zone->blank_select);
        $this->assign('district_select', $this->L_zone->blank_select);
        $this->assign('town_select', $this->L_zone->blank_select);
        $this->assign('blank_select', $this->L_zone->blank_select);
        $this->display();
    }
    
    public function pass_ajax_get_city_select()
    {
         $ProvinceId = (int)I('get.ProvinceId');
         $citySelect = $this->L_zone->getCitySelect($ProvinceId, -1, 'city_id', 'getDistrict(this.value)');
         $this->ajaxReturn(genReturn('y', 'ok', array('htm'=>$citySelect)));
    }
    
    public function pass_ajax_get_district_select()
    {
         $CityId = (int)I('get.CityId');
         $districtSelect = $this->L_zone->getDistrictSelect($CityId, -1, 'district_id', 'getTown(this.value)');
         $this->ajaxReturn(genReturn('y', 'ok', array('htm'=>$districtSelect)));
    }
    
    public function pass_ajax_get_town_select()
    {
         $DistrictId = (int)I('get.DistrictId');
         $townSelect = $this->L_zone->getTownSelect($DistrictId, -1, 'town_id');
         $this->ajaxReturn(genReturn('y', 'ok', array('htm'=>$townSelect)));
    }
}

